import axios from "axios"

const r = axios.create({
  baseURL: "http://47.95.192.129:3300/",
  // baseURL: "http://localhost:3300",
})
const requests = {
  get: (url: string, params?: { [propsKey: string]: string | number }) => r.get(url, {params}),
  post: (url: string, data?: { [propsKey: string]: string | number }) => r.post(url, data)
}

r.interceptors.response.use(value => value.data)

export const qqMusicApi = {
  // 为你推荐歌单
  getRecommendPlayList: () => {
    return requests.get("/recommend/playlist/u")
  },

  // 新歌推荐 0: 最新 1：内地，2：港台，3：欧美，4：韩国，5：日本
  getNewSongs: (type: number) => {
    return requests.get("/new/songs", {type})
  },

  // 新专辑推荐 默认为 1 // 1：内地，2：港台，3：欧美，4：韩国，5：日本，6：其他
  getNewAlbum: (type: number) => {
    return requests.get("/new/album", {type})
  },

  // 歌手列表
  getSingerList: () => {
    return requests.get("/singer/list")
  },

  // 获取歌单
  getSongList: (id: number) => {
    return requests.get("/songlist", {id})
  },

  // 获取歌曲下载地址
  getSongSrc: (id: number) => {
    return requests.get("/song/url", {id})
  },

  // 播放地址
  getSongPlaySrc: (list: number[]) => {
    return requests.get("/song/urls", {id: list.join(",")})
  },

  getSongPlaySrcSync: (mid: number) => {
    return requests.get(`https://u.y.qq.com/cgi-bin/musicu.fcg?loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data=%7B%22req_0%22%3A%7B%22module%22%3A%22vkey.GetVkeyServer%22%2C%22method%22%3A%22CgiGetVkey%22%2C%22param%22%3A%7B%22guid%22%3A%2210000%22%2C%22songmid%22%3A%5B%220${mid}%22%5D%2C%22songtype%22%3A%5B0%5D%2C%22uin%22%3A%220%22%2C%22loginflag%22%3A1%2C%22platform%22%3A%2220%22%7D%7D%2C%22comm%22%3A%7B%22uin%22%3A0%2C%22format%22%3A%22json%22%2C%22ct%22%3A20%2C%22cv%22%3A0%7D%7D`)
  },

  // 获取歌手信息
  getSingerInfo: (id: number) => {
    return requests.get("/singer/desc", {singermid: id})
  },
  // 获取歌手热门歌曲
  getSingerHotSong: (id: number, page = 1, num = 20) => {
    return requests.get("/singer/songs", {singermid: id, page, num})

  },
  // 获取歌手专辑
  getSingerAlbum: (id: number, pageNo = 1, pageSize = 20) => {
    return requests.get("/singer/album", {singermid: id, pageNo, pageSize})
  },

  // 获取专辑详情
  getAlbumDetail: (id: number) => {
    return requests.get("/album", {albummid: id})
  },

  // 获取专辑内歌曲
  getAlbumSongs: (id: number) => {
    return requests.get("/album/songs", {albummid: id})
  }
}
